package cn.imvc.app.domains;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;

import cn.imvc.app.commons.SystemConfig;

//显示类型：
//H5：101轮播图、102商品分类、103广告、104双列类型列表、105单列类型列表
public enum ImageFolder {
	
	imageFolder(0) {
        public String toString() {
        	WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext(); 
        	SystemConfig systemConfig = (SystemConfig)wac.getBean(SystemConfig.class);
        	return systemConfig.getImageFolder();
        }
    },
	goodsImageFolder(1) {
        public String toString() {
        	WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext(); 
        	SystemConfig systemConfig = (SystemConfig)wac.getBean(SystemConfig.class);
        	return systemConfig.getGoodsImageFolder();
        }
    },
	articleImageFolder(2) {
        public String toString() {
        	WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext(); 
        	SystemConfig systemConfig = (SystemConfig)wac.getBean(SystemConfig.class);
        	return systemConfig.getArticleImageFolder();
        }
    },
	userImageFolder(3) {
        public String toString() {
        	WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext(); 
        	SystemConfig systemConfig = (SystemConfig)wac.getBean(SystemConfig.class);
        	return systemConfig.getUserImageFolder();
        }
    },
	commentsImageFolder(4) {
        public String toString() {
        	WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext(); 
        	SystemConfig systemConfig = (SystemConfig)wac.getBean(SystemConfig.class);
        	return systemConfig.getCommentsImageFolder();
    	}
    },
	salesReturnImageFolder(5) {
        public String toString() {
        	WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext(); 
        	SystemConfig systemConfig = (SystemConfig)wac.getBean(SystemConfig.class);
        	return systemConfig.getSalesReturnImageFolder();
        }
    };
	
    private final Byte val;

    ImageFolder(int n) {
        val = (byte) n;
    }

    public Byte getValue() {
        return val;
    }
    public static ImageFolder getByIntValue(int n) {
        switch (n) {
            case 0:
                return imageFolder;
            case 1:
                return goodsImageFolder;
            case 2:
                return articleImageFolder;
            case 3:
                return userImageFolder;
            case 4:
                return commentsImageFolder;
            case 5:
                return salesReturnImageFolder;
            default:
                return null;
        }
    }
    
    public static final Map<Byte, String> elMap = new LinkedHashMap<Byte, String>();  
  
    static {
        for (ImageFolder s : EnumSet.allOf(ImageFolder.class)) {  
        	elMap.put(s.getValue(), s.toString());  
        }
    }
}